#pragma once

#include "zen_vap_helper.h"
#include "zen_vap_node.h"
#include "zen_vap_texture.h"
#include "zen_point.h"
#include <vector>
#include <mutex>

namespace Zen { namespace Vap {

	/*!
	 @class Sprite
	 @abstract This is the sprite that render a rect texture.
	 */
	class Sprite
	: public Node2d, public PartWithMatrix2d
	, public PartWithColor, public PartWithFlip
	, public PartWithTexture
	{
	public:
		Sprite();

		/*!
		 @function
		 @abstract the content size can be eigher the texture's size or the fixed size. <br>
		 Use setFixedSize to set the fixed size. <br>
		 If enableFixedSize(true), should also setFixedSize.
		 */
		void enableFixedSize(bool);
		
		auto isFixedSizeEnabled() { return m_is_fixed_sized; }

		/*!
		 @function
		 @abstract set the fixed size of content. (if not enabled, this has no effect)
		 */
		void setFixedSize(Size2 size);
		
		auto getFixedSize() { return m_fixed_size; }

		/*!
		 @function
		 @abstract get the content size. <br>
		 if fixed size enabled, this will return the fixed size. <br>
		 otherwise this is the texture's size (scaled).
		 */
		Size2 getContentSize();

		/*!
		 @function
		 @abstract update the content before draw.
		 @note If the subclass override, call Sprite::updateContent or impliment the logical.
		 */
		virtual void updateContent();

		virtual void draw() override;

		/*!
		 @function
		 @abstract set the shader selector. <br>
		 see ref class ShaderKit
		 */
		void setShaderSelector(ShaderKitTexture::SelectFunction s) { m_shaders = s; }

		auto getShaderSelector() { return m_shaders; }

	protected:
		DrawBufferTexture & getBuffer();
		ShaderKitTexture::SelectFunction m_shaders;

		void initR_();
		void drawR_();

	protected:
		Vec4 m_texture_rect_converted = { 0, 0, 1, 1 };

		/// texture.
		Size2 m_fixed_size = { 0, 0 };
		/// use m_fixed_size or m_texture_size as content size.
		bool m_is_fixed_sized = false;
	};
}}
